<script setup>
  import { onMounted, ref, reactive, computed } from 'vue'
  import { onLoad, onShow } from '@dcloudio/uni-app'
  import { http } from '@/utils/http.js'
  import { parseTime } from '@/utils/index.js'
  import Api from './api/index.js'
  const __Api = new Api()
  import { useUsercodeStore } from '@/store/usercode.js'

  const isAll = ref(true)
  const userInfo = ref()
  const page = ref(1)
  function getList() {}
  function returnTimeTxt(e) {
    return parseTime(e)
  }
  function goBack() {
    console.log(1)
    uni.navigateBack()
  }
  function changeState(item) {
    getgoodsList.value = []
    isAll.value = item
    page.value = 1
    Init()
  }
  function scrolltolower() {
    page.value++
    Init()
  }
  const getgoodsList = ref([])
  function Init() {
    __Api
      .drawlist({
        box_id: box_id.value,
        page: page.value,
        is_own: isAll.value ? null : 1,
      })
      .then((res) => {
        getgoodsList.value = getgoodsList.value.concat(res.data)
      })
  }
  const box_id = ref('')
  onLoad((options) => {
    const userCodeStore = useUsercodeStore()
    userInfo.value = userCodeStore.usercode
    box_id.value = options.box_id
    Init()
  })
  onShow(() => {})
</script>

<template>
  <view class="warp">
    <view class="war-top">
      <view class="war-back" @click="goBack">
        <view class="back-aim"> </view>
      </view>
    </view>
    <view class="top_box">
      <image
        class="topBg"
        src="https://ojqn.wm2177.com/wechat_imgs/gold/top-bg.jpg"
        mode="widthFix"
      ></image>
      <view class="select_box">
        <image
          @click="changeState(true)"
          :src="`https://ojqn.wm2177.com/wechat_imgs/gold/logs${
            isAll ? '-select' : ''
          }.png`"
          mode="widthFix"
        ></image>
        <image
          @click="changeState(false)"
          :src="`https://ojqn.wm2177.com/wechat_imgs/gold/my-logss${
            !isAll ? '-select' : ''
          }.png`"
          mode="widthFix"
        ></image>
      </view>
      <scroll-view
        class="scrollBox"
        scroll-y="true"
        :lower-threshold="120"
        @scrolltolower="scrolltolower"
      >
        <view
          class="listItem"
          v-for="(item, index) in getgoodsList"
          :key="index"
        >
          <view class="leftBox">
            <image
              class="icon"
              :src="isAll ? item.himg : userInfo.himg"
              mode="widthFix"
            ></image>
            <view class="" style="margin-left: 20rpx">
              <view class="name">
                {{ isAll ? item.nickname : userInfo.nickname }}
              </view>
              <view class="time"> {{ item.createtime }} </view>
            </view>
          </view>
          <image
            style="width: 100rpx"
            :src="item.goods_img"
            mode="widthFix"
          ></image>
        </view>
      </scroll-view>
      <!-- 背包 -->
    </view>
    <view class="content">
      <image
        style="width: 100%"
        src="https://ojqn.wm2177.com/wechat_imgs/gold/bottom-bg.png"
        mode="widthFix"
      ></image>
      <!-- transform: rotate(30deg); -->
    </view>
  </view>
</template>
<style lang="less" scoped>
  .war-top {
    padding-left: 18rpx;
    position: fixed;
    z-index: 99999;
    top: 88rpx;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    .war-back {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 57rpx;
      height: 57rpx;
      background-color: rgba(7, 1, 53, 0.5);
      border-radius: 50%;

      .back-aim {
        width: 20rpx;
        height: 20rpx;
        border-top: 4rpx solid #fff;
        border-left: 4rpx solid #fff;
        transform: rotate(-45deg);
      }
    }
  }
  .warp {
    width: 750rpx;
    height: 100vh;
    overflow: hidden;
    .top_box {
      position: relative;

      .topBg {
        width: 750rpx;
      }
      .scrollBox {
        width: 100%;
        height: 1100rpx;
        position: absolute;
        z-index: 1;
        top: 420rpx;
        display: flex;
        justify-content: center;
        .listItem {
          margin: 0 auto;
          width: 690rpx;
          height: 180rpx;
          display: flex;
          align-items: center;
          justify-content: space-between;
          background-image: url('https://ojqn.wm2177.com/wechat_imgs/gold/user-bg.png');
          background-size: 100%;
          padding: 20rpx 60rpx;
          box-sizing: border-box;
          margin-bottom: 40rpx;
          .leftBox {
            display: flex;
            align-items: center;
            color: #462917;
            font-size: 24rpx;
            .name {
              width: 80rpx;
              overflow: hidden; /* 确保超出容器的文本被隐藏 */
              white-space: nowrap; /* 防止文本换行 */
              text-overflow: ellipsis;
            }
            .icon {
              width: 100rpx;
              height: 100rpx;
              border-radius: 100%;
              border: 4rpx solid #462917;
            }
          }
        }
      }
      .select_box {
        position: absolute;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1;
        top: 280rpx;
        width: 100%;
        image {
          width: 200rpx;
          margin: 0 20rpx;
        }
      }
    }
    .content {
      position: relative;
      width: 750rpx;

      .goldsBox {
        width: 750rpx;
        height: 700rpx;
        background: red;
        position: absolute;
        .goldItem {
          position: absolute;
          z-index: 3;
        }
      }
    }
  }

  image {
    display: block;
    vertical-align: bottom; /* 或者使用 top 或 middle，根据需求 */
  }
</style>
